package com.kkd.kkdapp.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.BaseActivity;
import com.kkd.kkdapp.fragment.ManageAwardRegularFragment;

/**
 * 理财奖励
 * 
 * @author mty
 * 
 */
public class ManageAwardActivity extends BaseActivity implements
		OnClickListener {

	private RelativeLayout find_img; // 后退
	private FrameLayout regular_frame;
	ManageAwardRegularFragment manageAwardRegularFragment1 = ManageAwardRegularFragment
			.getInstance(1);
	ManageAwardRegularFragment manageAwardRegularFragment2 = ManageAwardRegularFragment
			.getInstance(2);
	private View regular_button;
	private TextView regular_tv;
	private View regular_view;
	private View finc_button;
	private TextView finc_tv;
	private View finc_view;
	private FrameLayout finc_frame;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_manage_award);
		initView();
		setListener();
		initFragmentView();
	}

	/**
	 * 初始化组件
	 */
	public void initView() {
		find_img = (RelativeLayout) this.findViewById(R.id.find_img);
		regular_frame = (FrameLayout) this.findViewById(R.id.regular_frame);
		finc_frame = (FrameLayout) this.findViewById(R.id.finc_frame);
		regular_button = this.findViewById(R.id.regular_button);
		regular_tv = (TextView) this.findViewById(R.id.regular_tv);
		regular_view = this.findViewById(R.id.regular_view);
		finc_button = this.findViewById(R.id.finc_button);
		finc_tv = (TextView) this.findViewById(R.id.finc_tv);
		finc_view = this.findViewById(R.id.finc_view);
	}

	/**
	 * 注册监听
	 */
	public void setListener() {
		find_img.setOnClickListener(this);
		regular_button.setOnClickListener(this);
		finc_button.setOnClickListener(this);
	}

	private void initFragmentView() {
		FragmentTransaction tran = getSupportFragmentManager()
				.beginTransaction();
		tran.replace(R.id.regular_frame, manageAwardRegularFragment1);
		tran.replace(R.id.finc_frame, manageAwardRegularFragment2);
		tran.commit();
		setFragmentView(1);
	}

	private void setFragmentView(int index) {
		setSelectColor(index);
		switch (index) {
		case 1:
			regular_frame.setVisibility(View.VISIBLE);
			finc_frame.setVisibility(View.GONE);
			break;

		case 2:
			regular_frame.setVisibility(View.GONE);
			finc_frame.setVisibility(View.VISIBLE);
			break;

		default:
			break;
		}
	}

	private void setSelectColor(int index) {
		switch (index) {
		case 1:
			regular_tv.setTextColor(Color.parseColor("#543c9f"));
			regular_view.setVisibility(View.VISIBLE);
			finc_tv.setTextColor(Color.parseColor("#333333"));
			finc_view.setVisibility(View.GONE);
			break;

		case 2:
			regular_tv.setTextColor(Color.parseColor("#333333"));
			regular_view.setVisibility(View.GONE);
			finc_tv.setTextColor(Color.parseColor("#543c9f"));
			finc_view.setVisibility(View.VISIBLE);
			break;

		default:
			break;
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.find_img:
			finish();
			break;

		case R.id.regular_button:
			setFragmentView(1);
			break;

		case R.id.finc_button:
			setFragmentView(2);
			break;
		}
	}

}
